package com.neuedu.web.controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author 金山
 * 项目：javaweb
 * site: https://blog.fulfill.com.cn
 *
 *   http://127.0.0.1:8080/web/tab
 *
 *
 * 描述
 * @data 2024/11/149:51
 */
@WebServlet(urlPatterns = "/tab")
public class TableServlet  extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //需要 设置contentType  告诉浏览器  媒体类型 MIME 类型

        //告诉浏览器输出 html
        resp.setContentType("text/html;charset=utf-8");


        StringBuffer htmlTable =new StringBuffer();
        htmlTable.append("<table width='100%' >");
        htmlTable.append("<tr>");
        htmlTable.append("      <td>");
        htmlTable.append("      序号");
        htmlTable.append("      </td>");
        htmlTable.append("      <td>");
        htmlTable.append("      姓名");
        htmlTable.append("      </td>");
        htmlTable.append("      <td>");
        htmlTable.append("      性别");
        htmlTable.append("      </td>");
        htmlTable.append("</tr>");

        for (int i = 0; i < 10; i++) {
            htmlTable.append("<tr>");
            htmlTable.append("      <td>");
            htmlTable.append( i);
            htmlTable.append("      </td>");
            htmlTable.append("      <td>");
            htmlTable.append("      姓名"+i);
            htmlTable.append("      </td>");
            htmlTable.append("      <td>");
            htmlTable.append("      性别"+i);
            htmlTable.append("      </td>");
            htmlTable.append("</tr>");
        }
        htmlTable.append("</table>");

        PrintWriter out = resp.getWriter();

        out.write(htmlTable.toString());

        out.flush();
        out.close();
    }
}
